package com.ruoyi.web.controller.performance;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.performance.domain.AssessmentItems;
import com.ruoyi.performance.service.IAssessmentItemsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 考核项目Controller
 * 
 * @author eden
 * @date 2023-05-19
 */
@RestController
@RequestMapping("/performance/items")
public class AssessmentItemsController extends BaseController
{
    @Autowired
    private IAssessmentItemsService assessmentItemsService;

    /**
     * 查询考核项目列表
     */
    @PreAuthorize("@ss.hasPermi('performance:items:list')")
    @GetMapping("/list")
    public TableDataInfo list(AssessmentItems assessmentItems)
    {
        startPage();
        List<AssessmentItems> list = assessmentItemsService.selectAssessmentItemsList(assessmentItems);
        return getDataTable(list);
    }

    /**
     * 导出考核项目列表
     */
    @PreAuthorize("@ss.hasPermi('performance:items:export')")
    @Log(title = "考核项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssessmentItems assessmentItems)
    {
        List<AssessmentItems> list = assessmentItemsService.selectAssessmentItemsList(assessmentItems);
        ExcelUtil<AssessmentItems> util = new ExcelUtil<AssessmentItems>(AssessmentItems.class);
        util.exportExcel(response, list, "考核项目数据");
    }

    /**
     * 获取考核项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('performance:items:query')")
    @GetMapping(value = "/{itemId}")
    public AjaxResult getInfo(@PathVariable("itemId") Long itemId)
    {
        return success(assessmentItemsService.selectAssessmentItemsByItemId(itemId));
    }

    /**
     * 新增考核项目
     */
    @PreAuthorize("@ss.hasPermi('performance:items:add')")
    @Log(title = "考核项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssessmentItems assessmentItems)
    {
        return toAjax(assessmentItemsService.insertAssessmentItems(assessmentItems));
    }

    /**
     * 修改考核项目
     */
    @PreAuthorize("@ss.hasPermi('performance:items:edit')")
    @Log(title = "考核项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssessmentItems assessmentItems)
    {
        return toAjax(assessmentItemsService.updateAssessmentItems(assessmentItems));
    }

    /**
     * 删除考核项目
     */
    @PreAuthorize("@ss.hasPermi('performance:items:remove')")
    @Log(title = "考核项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{itemIds}")
    public AjaxResult remove(@PathVariable Long[] itemIds)
    {
        return toAjax(assessmentItemsService.deleteAssessmentItemsByItemIds(itemIds));
    }
}
